home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Softdisk Supreme
/
Softdisk Supreme.iso
/
pc
/
DSK Files
/
0-49
/
SD008b.dsk
/
SORT.ROUTINE.bas
< prev
next >
Wrap
BASIC Source File
|
2003-06-12
|
2KB
|
83 lines
100 REM THE ACTUAL SORT
110 REM SUBROUTINE IS IN LINES
120 REM 390 - 640
130 REM
140 REM THE SUBROUTINE CAN BE
150 REM PUT ANYWHERE BUT THE
160 REM SORT WILL BE FASTER IF
170 REM YOU PUT IT EARLY IN
180 REM THE PROGRAM
190 REM
200 REM IF YOU REMOVE ALL THE
210 REM 'REM' STATEMENTS THE
220 REM ROUTINE WILL SORT 100
230 REM FOUR DIGIT NUMBERS IN
240 REM ABOUT 45 SECONDS
250 REM
260 REM WHEN USING THE ROUTINE
270 REM ALWAYS 'DIM' ONE MORE
280 REM ELEMENT IN YOUR ARRAYS
290 REM THEN YOU WILL NEED
300 REM (IF YOU ARE SORTING
310 REM 100 NUMBERS 'DIM'
320 REM YOUR ARRAYS TO 101)
330 REM
340 TEXT : HOME : GOTO 700
350 REM
360 REM ROUTINE AT 390 INSERTS
370 REM A NUMBER IN THE LIST
380 REM
390 FOR Q = CO TO X STEP -OE:EN(Q +OE) = EN(Q): NEXT Q:CO = CO +OE:EN(X) = ST(CO): RETURN
400 EN(OE) = ST(OE):CO = OE
410 REM
420 REM LN 450 CHECKS IF SORT
430 REM IS FINISHED
440 REM
450 IF CO >N THEN FOR X = 1 TO N:EN(X) = EN(X +1): NEXT : RETURN
460 REM
470 REM LNS 620-640 CHECK IF
480 REM THE NUMBER IS LESS
490 REM THEN THE OTHER NUMBERS
500 REM IN THE LIST ,IF IT IS
510 REM THEN IT CALLS THE
520 REM ROUTINE AT 390 TO
530 REM INSERT IT IN THE LIST
540 REM IF IT ISN'T THE NUMBER
550 REM IS PUT AT THE END
560 REM
570 REM TO SORT NUMBERS FROM
580 REM LARGE TO SMALL CHANGE
590 REM THE '<' IN LINE 620 TO
600 REM A '>'
610 REM
620 FOR X = OE TO CO: IF ST(CO +OE) <EN(X) THEN GOSUB 390: GOTO 450
630 NEXT
640 CO = CO +OE:EN(X) = ST(CO): GOTO 450
650 REM
660 REM LINES 700 - 920
670 REM ARE JUST I/O ROUTINES
680 REM TO SHOW THE SORT
690 REM
700 DIM ST(101),EN(101):N = 0:OE = 1
710 PRINT "HOW MANY NUMBERS TO SORT"
720 PRINT "(THE ARRAYS ARE SET UP FOR A MAXIMUN OF 100)";: INPUT N
730 FOR X = OE TO N:ST(X) = INT( RND(22) *1000): NEXT
740 REM
750 REM LINE 890 CALLS THE
760 REM SORT ,SET N TO THE
770 REM NUMBER OF ITEMS TO BE
780 REM SORTED AND OE = 1
790 REM ST(X) IS THE ARRAY
800 REM THAT IS SORTED ,THE
810 REM NUMBERS ARE PUT INTO
820 REM EN(X).
830 REM
840 REM TO SORT STRINGS JUST
850 REM USE A STRING VARIABLE
860 REM INSTEAD OF A NUMBERIC
870 REM ONE.
880 REM
890 GOSUB 400
900 HOME
910 PRINT "ORIGINAL" TAB( 10)"SORTED": POKE 34,1
920 FOR X = OE TO N: PRINT ST(X); TAB( 10)EN(X): NEXT